<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@include file="/WEB-INF/base.jspf"%>
<!DOCTYPE html>
<html>
<head>
<title>日常返水管理</title>
<style>
	#table-baimingdan {
		margin-top:16px;
	}
	.hidden-td {
		display:none;
	}
		.modal-dialog {
		max-width: 1000px;
	}
	
	.p-c-flexwrapper {
		display:flex;
		align-items:center;
		margin-right:16px;
		margin-bottom:16px;
	}
	
	.p-c-flexwrapper > span {
		width:110px;
	}
	.p-c-flexwrapper > .form-control {
		width:130px;
	}
	#addAndEditModal .modal-body {
		display:flex;
		flex-wrap:wrap;
	}
	.modal-dialog {
		max-width: 1000px;
	}
	
	table th,table tr,table td {
	text-align: center;
	vertical-align:middle;
	}
</style>
</head>
<body>
	<div class="div-c-controlBtns" style="display:flex;justify-content:flex-start;">
		<button class="btn btn-primary" id="button-i-addNewZongDaiLi">新增</button>
	</div>   	
	<table id="table-baimingdan" class="class-tableDataTable table-normal-datatables table table-striped table-bordered table-hover">
		<thead>
			<tr>
				<th style="display:none;"></th>
				<th style="display:none;"></th>
				<th >返水类型</th>
				<th >所需充值金额</th>
				<th >所需打码量</th>
				<th id="money">返水比率</th>
				<th >状态</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>

<div class="modal fade" id="addNewIpBaiFanShui" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="myModalLabel">修改返水规则</h5>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                 <br><span style="font-size:12px;color:red;"> 注意：比率格式为1以下的小数 格式：0.20</span>
            </div>
            <div class="modal-body">
            	<input hidden="hidden" class="fandian-auto" id="input-i-id" />
            	<input hidden="hidden" class="fandian-auto" id="input-i-type" />
            	<p style="display:flex;align-items:center;"><span style="width:128px;display:inline-block;">所需充值金额：</span><input style="width:200px;" class="fandian-auto form-control" required id="input-i-jine" /></p>
            	<p style="display:flex;align-items:center;"><span style="width:128px;display:inline-block;">所需打码量：</span><input style="width:200px;"  class="fandian-auto form-control" required id="input-i-damal" /></p>
            	<p style="display:flex;align-items:center;"><span style="width:128px;display:inline-block;">返水比率：</span><input style="width:200px;"  class="fandian-auto form-control" required id="input-i-fdianlv" /></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="btn-i-addNewWhiteIp">提交更改</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

	<!-- 模态框（Modal）新增 -->
	
 	 	<div class="modal fade" id="addAndEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-header">
		            <h5 class="modal-title" id="myModalLabel">添加返水规则</h5>
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
		                 <br><span style="font-size:12px;color:red;"> 注意：比率格式为1以下的小数 格式：0.20</span>
		            </div>
		            <form>
		            <div class="modal-body">
		            	<input id="input-i-id" hidden="hidden" class="input-auto" /> 
		            	<p class="p-c-flexwrapper"><span>反水类型：</span>
		            	<select id="input-i-leixing" required class="input-auto form-control" >
		            		<option value="1">每日类型</option>
		            		<option value="2">每月类型</option>
		            	</select>
		            	</p>
		            	<p class="p-c-flexwrapper"><span style="width:150px;">所需充值金额：</span><input id="input-i-money" required class="input-auto form-control" /></p>
		            	<p class="p-c-flexwrapper p-special2"><span>返水比率：</span><input id="input-i-fanshuilv" type='text' class="form-control" /></p>
		            	<p class="p-c-flexwrapper p-special1"><span style="width:150px;">所需打码量：</span><input id="input-i-damaliang" type='text' class="form-control" /></p>
		            </div>
		            </form>
		            <div class="modal-footer">
		                <button type="button" class="btn btn-primary" id="button-i-submitZongDaiLi">提交</button>
		                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		            </div>
		            </div>
		            </div>
		            </div>


<script type="text/javascript" src="/js/zhengzeTools.js"></script>
	<script>
	
	$("#button-i-addNewZongDaiLi").on("click",function(){
		$("#addAndEditModal").modal("show")
	})
	
	$("#button-i-submitZongDaiLi").on("click",function(){
		var vals = $("#input-i-leixing").val();
		$("#addAndEditModal").modal("hide")
		if(vals==1){
			vals = "每日返水";
		}else{
			vals = "每月返水";
		}
		$.ajax({
			type: "POST",
       	 	url: "/zhgl/insertBackwaterSetup.do",
       	 	data:{
       	 		"name":vals,
       	 		"type":$("#input-i-leixing").val(),
       	 		"jine":$("#input-i-money").val(),
       	 		"damal":$("#input-i-damaliang").val(),
       	 		"fdianlv":$("#input-i-fanshuilv").val(),
       	 		},
       	 	success:function(data){
       		 	alert(data.data);
	   	 		$("#table-baimingdan").DataTable().ajax.reload();
       	 	}
		})
	})
	
		bindJinYongQiYongSwitch("#table-baimingdan", "/zhgl/enableBackWaterSetup.do", "state")	
		$("#table-baimingdan").on("click", ".btn-editBaiMingDanItem", function(e) {
			var $tr = $(e.currentTarget).closest("tr")
			$("#addNewIpBaiFanShui .fandian-auto").each(function(index, element) {
				element.value = $tr.find("." + element.id.split("-")[2] + "-edit-td").text()
			})
			$("#addNewIpBaiFanShui").modal("show")
		})
		var dataTable = $("#table-baimingdan").DataTable({
		      // "bPaginate": true,
		      "bLengthChange": true,      
		      "bSort": false,
		      "bAutoWidth": false,
		      'aLengthMenu':[5, 20],
		       "searching": false,
		       "dom": "t<'tableinfo'i<'tableSearch'p>l>",
		       "language": {//语言设置  
		            "lengthMenu": "每页显示 _MENU_ 条记录",     
		            "zeroRecords": "没有检索到数据",     
		            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",     
		            "info": "没有数据",     
		            "oPaginate": {     
		                "sFirst": "首页",     
		                "sPrevious": "前一页",     
		                "sNext": "后一页",     
		                "sLast": "尾页"    
		          	},
		            "search":"搜索:",
		            "infoFiltered":   "(从  _MAX_ 记录中搜索出结果)",
		            "infoEmpty":      "没有找到匹配的信息",
		         },
		         "drawCallback": function( settings ) {
		        	 $(".input-c-mySwitch").bootstrapSwitch()
		         },
		         "ajax": {
		        	 "type": "POST",
		        	 "url": "/zhgl/findAllBackWaterSetup.do",
		        	 "dataSrc": function(json) {
		        		 var newJson = json.data
		        		 for (var i = 0; i < newJson.length; i++) {
		         			 var item = newJson[i]
		         			 var stateValue = ""
		        			 if (item.state == "1") {
		        				 stateValue = "checked"
		        			 } else {
		        				 stateValue = ""
		        			 }
		        		 	item.state = "<input class='input-c-mySwitch' data-size='small' type='checkbox' " + stateValue + " data-on-text='启用' data-on-color='success' data-off-color='danger' data-off-text='禁用' />"
		        		 }
		        		 return newJson
		        	 },
		         },
 		         "columns": [
							 {"data": "id", "className": "id-edit-td hidden-td"},
							 {"data": "type", "className": "type-edit-td hidden-td"},
							 {"data": "name", "className": "name-edit-td"},
		                     {"data": "jine", "className": "jine-edit-td"},
		                     {"data": "damal", "className": "damal-edit-td"},
		                     {"data": "fdianlv", "className": "fdianlv-edit-td"},
		                     {"data": "state", },
		                     {"data": null, "defaultContent": "<button class='btn btn-info btn-editBaiMingDanItem btn-sm'>修改</button> <button class='btn btn-danger btn-c-delBankInfo btn-sm butt-shanchu'>删除</button>"},
		                 ]      
		   		 })
		   		 insertSearchBtn()
		   		 
			var obj = {
				btnName: "#btn-i-addNewWhiteIp",
				divName: "#addNewIpBaiFanShui",
				isRegArray: [
				             {inputValue: function() {
				            	 return $("#input-i-jine").val()
				             }, regValue: /^[0-9]+([.]{1}[0-9]{1,2})?$/, noticeText:"返水金额有误，请重新填写"},
				             {inputValue: function() {
				            	 return $("#input-i-damal").val()
				             }, regValue: /^[0-9]+([.]{1}[0-9]{1,2})?$/, noticeText:"返水打码量有误，请重新填写"},
				             {inputValue: function() {
				            	 return $("#input-i-fdianlv").val()
				             }, regValue: /^[0-9]+([.]{1}[0-9]{1,2})?$/, noticeText:"返水率有误，请重新填写"},
				             ],
			}
			checkFormMethod(obj, function() {
				var newData = {}
				$("#addNewIpBaiFanShui .fandian-auto").each(function(index, element) {
					newData[element.id.split("-")[2]] = element.value
				})
				$('#addNewIpBaiFanShui').modal("hide")
				var newRequest = {
					type: "post",
					url: "/zhgl/updateBackWaterSetup.do",
					data: newData,
					success: function(data) {
						var obj = JSON.parse(data);
					 	alert(obj.data);
			   	 		$("#table-baimingdan").DataTable().ajax.reload();
					},
					error: function(status) {
					}
				}
				ajax(newRequest)
			})	
			
		$("#table-baimingdan").on("click", ".butt-shanchu", function(e) {
			var fals = true
			var i
			var $tr = $(e.currentTarget).closest("tr")
			$("#addNewIpBaiFanShui .fandian-auto").each(function(index, element) {
				element.value = $tr.find("." + element.id.split("-")[2] + "-edit-td").text()
				if(fals){
					i = element.value
					fals = false
				}
			})
			$.ajax({
				type: "POST",
	       	 	url: "/zhgl/deleteBackwaterSetup.do",
	       	 	data:{
	       	 		"id":i,
	       	 		},
	       	 	success:function(data){
	       		 	alert(data.data);
		   	 		$("#table-baimingdan").DataTable().ajax.reload();
	       	 	}
			})
	})	
	</script>
</body>
</html>